package ccuserinterface;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import datamodels.Conference;
import datamodels.GlobalDataStore;
import datamodels.Role;
import datamodels.User;
/**
 * This class will display information about all of the manuscripts that have been submitted to the conference.
 * @author Alan Meaker
 *
 */
@SuppressWarnings("serial")
public class ViewManuscriptsPage extends JFrame
{
	JTable my_jtable;
	JScrollPane my_scroll_pane;
	GlobalDataStore my_data_store;
	JButton my_back_btn;
	JButton my_decision;
	Role my_role;
	Conference my_conference;
	User my_user;
	/**
	 * constructor.
	 */
	public ViewManuscriptsPage(GlobalDataStore the_data_store, Role the_role, Conference the_conference, User the_user)
	{
		super();
		my_data_store = the_data_store;
		my_role = the_role;
		my_conference = the_conference;
		my_user = the_user;
    	setTitle("View Manuscripts");
        setLayout(null);
        setVisible(true);
        setPreferredSize(new Dimension(800,600));
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
		setupGUI();
		pack();
	}
	/**
	 * set up the frame using JTable. 
	 */
	private void setupGUI()
	{
		//header.
		Object[] column_names = {"Title of Manuscript", "Author", "Number of Reviews", "Decision Status"};
		//body
		final Object[][] my_lines = new Object[my_data_store.getCurrentConference().getManuscripts().size()][5];
		for (int i = 0; i < my_data_store.getCurrentConference().getManuscripts().size(); i++)
		{
			my_lines[i][0] = my_data_store.getCurrentConference().getManuscripts().get(i).getTitle();
			my_lines[i][1] = my_data_store.getCurrentConference().getManuscripts().get(i).getAuthor().getName();
			my_lines[i][2] = my_data_store.getCurrentConference().getManuscripts().get(i).getReviews().size();
			my_lines[i][3] = my_data_store.getCurrentConference().getManuscripts().get(i).getCurrentStatus();
		}
		my_jtable = new JTable(my_lines, column_names);

		my_scroll_pane = new JScrollPane(my_jtable);
		my_jtable.setFillsViewportHeight(true);
		my_jtable.setEnabled(false);
		my_scroll_pane.setBounds(new Rectangle(0,0,800,500));
		add(my_scroll_pane);
		//Setup back button
		my_back_btn = ImageCreator.createButton("  Go back", new Rectangle(30,520,140,40));
		my_back_btn.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				
				dispose(); 
				new ChooseUserStory(my_role, my_conference, my_user, my_data_store);
				
			}
		});
		add(my_back_btn);
		my_decision = ImageCreator.createButton(" Change Decision", new Rectangle(620, 520, 140, 40));
		my_decision.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				dispose();
				new ManuscriptListFrame(my_conference, my_user, my_data_store);
				
			}
			
		});
		add(my_decision);
		
		
	
	}
}
